import 'dart:io';

void main() {
  // Device status initialization
  bool lightsOn = false;
  int thermostatTemp = 20; // Default 20°C
  bool securityArmed = false;

  const int minTemp = 15;
  const int maxTemp = 30;

  while (true) {
    // Display menu options
    print('Smart Home Automation Menu:');
    print('1. Toggle Lights (Currently ${lightsOn ? "On" : "Off"})');
    print('2. Set Thermostat (Current Temperature: $thermostatTemp°C)');
    print('3. Arm/Disarm Security System (Currently ${securityArmed ? "Armed" : "Disarmed"})');
    print('4. View System Status');
    print('5. Exit');
    stdout.write('Enter your choice (1-5): ');
    String? choice = stdin.readLineSync();

    // Handling the choices
    if (choice == '1') {
      // Toggle lights
      lightsOn = !lightsOn;
      print('Lights are now ${lightsOn ? "On" : "Off"}');
    } else if (choice == '2') {
      // Set thermostat
      stdout.write('Enter temperature ($minTemp°C to $maxTemp°C): ');
      int? temp = int.tryParse(stdin.readLineSync()!);
      if (temp != null && temp >= minTemp && temp <= maxTemp) {
        thermostatTemp = temp;
        print('Thermostat set to $thermostatTemp°C');
      } else {
        print('Invalid temperature! Please enter a value between $minTemp and $maxTemp.');
      }
    } else if (choice == '3') {
      // Arm/Disarm security system
      securityArmed = !securityArmed;
      print('Security system is now ${securityArmed ? "Armed" : "Disarmed"}');
    } else if (choice == '4') {
      // View system status
      String temperatureStatus = '';
      if (thermostatTemp % 3 == 0 && thermostatTemp % 5 == 0) {
        temperatureStatus = 'Perfect Day';
      } else if (thermostatTemp % 3 == 0) {
        temperatureStatus = 'Cool Day';
      } else if (thermostatTemp % 5 == 0) {
        temperatureStatus = 'Warm Day';
      }

      print('System Status:');
      print('Lights: ${lightsOn ? "ON" : "OFF"}');
      print('Thermostat: $thermostatTemp°C ${temperatureStatus.isNotEmpty ? "($temperatureStatus)" : ""}');
      print('Security System: ${securityArmed ? "ARMED" : "DISARMED"}');
    } else if (choice == '5') {
      // Exit the program
      print('Exiting...');
      break;
    } else {
      print('Invalid choice! Please select a valid option.');
    }
  }
}
